package com.atwisdom.star.dcs.pojo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value ="RealTimeControl",autoResultMap = true)
public class RealTimeControl extends BaseEntity{
    @TableField(exist = false)
    private static final long serialVersionUID =-2L;
    //报警类型，BJA、BJB、ZBJ
    public final static String ALARM_TYPE_BJA = "BJA";
    public final static String ALARM_TYPE_BJB = "BJB";
    public final static String ALARM_TYPE_ZBJ = "ZBJ";
    public final static String ALARM_TYPE_BJ = "BJ";
    public final static String CONTROL_TYPE_YZZB = "YZZB";

    //数采配置树结构全路径
    @TableField(value = "path")
    private String path;
    //节点设备分类，如：点焊、冲压等设备类型
    @TableField(value = "category")
    private String category;
    //节点设备编码
    @TableField(value = "code")
    private String code;
    //节点报警名称
    @TableField(value = "name")
    private String name;
    //节点id
    @TableField(value = "nodeId")
    private Short nodeId;
    //信号类型，0：模拟，1：数字
    @TableField(value = "kind")
    private Short kind;
    //当前生产品番
    @TableField(value = "pf")
    private String pf;
    //报警开始标识
    @TableField(value = "startFlag")
    private int startFlag;
    //报警停止标识
    @TableField(value = "stopFlag")
    private int stopFlag;
    //开始报警时间戳
    @TableField(value = "startTimestamp")
    private long startTimestamp;
    //报警时长
    @TableField(value = "duration")
    private long duration;
    //当前报警时间戳
    @TableField(value = "endTimestamp")
    private long endTimestamp;
    //是否异常报警 1 报警类型，2 开关机类型运转
    @TableField(value = "controlType")
    private int controlType;
    //节点说明
    @TableField(value = "remark")
    private String remark;

    /**
     * 检查是否为报警字段
     * @param alarmName 名称
     * @return 如果是报警字段 返回true,否则返回false
     */
    public static boolean checkAlarm(String alarmName){
        if(alarmName.contains(RealTimeControl.ALARM_TYPE_BJA)){
            return true;
        }else if(alarmName.contains(RealTimeControl.ALARM_TYPE_BJB)){
            return true;
        }else if(alarmName.contains(RealTimeControl.ALARM_TYPE_ZBJ)){
            return true;
        }else if(alarmName.contains(RealTimeControl.ALARM_TYPE_BJ)){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 检查是否为运转启字段
     * @param controlName 名称
     * @return 如果是报警字段 返回true,否则返回false
     */
    public static boolean checkControlReady(String controlName){
        if(controlName.lastIndexOf(RealTimeControl.CONTROL_TYPE_YZZB) >0){
            return true;
        }else{
            return false;
        }
    }
}